package com.batchaps.menu;

import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.media.Manager;

import com.batchaps.classes.TwoPersonPlay;

public class MenuManager{
	
	//screan
	public MainMenu mainMenu;
	HelpMenu helpMenu;
	AboutMenu aboutMenu;
	ChoiceKindPlayMenu choiceKindPlay;
	KindOfIntelligent kindOfIntelligent;
	
	GameMenu newGame;
	
	//background
	Image imgBang;
	
	public MenuManager(int width , int height) {
		// TODO Auto-generated constructor stub
		mainMenu = new MainMenu(width, height);
		helpMenu = new HelpMenu(width, height);
		aboutMenu = new AboutMenu(width, height);
		choiceKindPlay = new ChoiceKindPlayMenu();
		kindOfIntelligent = new KindOfIntelligent();
		
		newGame = new GameMenu();
		
		try {
			imgBang = Image.createImage("/menu/bang.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public int IsClick(int x , int y)
	{
		switch (mainMenu.iMenu) {
		case 0:
			return mainMenu.IsClick(x, y);
		case 1:
			if(choiceKindPlay.IsClick(x, y) == 1)
				mainMenu.iMenu = 4;
			if(choiceKindPlay.IsClick(x, y) == 2)
			{
				mainMenu.iMenu = 6;
				//newGame = new GameMenu();
				newGame.UpdateKindOfPlay(new TwoPersonPlay(newGame));
			}
			return 1;
		case 2:
			if(helpMenu.IsClick(x, y) == 1)
				mainMenu.iMenu = 0;
			return 0;
		case 3:
			if(aboutMenu.IsClick(x, y) == 1)
				mainMenu.iMenu = 0;
			return 3;
		case 4://choice kindof intelligen
			int intell = kindOfIntelligent.IsClick(x, y);
			//newgame = new (intell);
			if(intell != 0)
			{
				mainMenu.iMenu = 6;
				//newGame = new GameMenu();
			}
			return 4;
		case 5://exit
			return 5;
		case 6://play game
			newGame.IsClick(x, y);
			return 6;
		default:
			break;
		}
		return 0;
	}
	
	public void pointerPress(int x , int y)
	{
		if(mainMenu.iMenu == 6)
			newGame.pointerPress(x, y);
	}
	
	public void Update()
	{
		if(mainMenu.iMenu == 6)
			newGame.Update();
	}
	
	public void Draw(Graphics g)
	{
		if(mainMenu.iMenu != 6)
		{
			g.drawImage( imgBang, 30, 70, 0);
		}
		
		switch (mainMenu.iMenu) {
		case 0:
			mainMenu.Draw(g);
			break;
		case 1:
			choiceKindPlay.Draw(g);
			break;
		case 2:
			helpMenu.Draw(g);
			break;
		case 3:
			aboutMenu.Draw(g);
			break;
		case 4:
			kindOfIntelligent.Draw(g);
			break;
		case 6://playgame
			if(newGame != null)
				newGame.Draw(g);
			break;
		default:
			break;
		}
		
		
		
	}
	
}
